<?php
namespace Index\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function index()
    {
        if (empty($_SESSION['id'])) {
            if (IS_POST) {
                $user_name = I("post.user_name");
                $password = md5(I("post.password"));
                $m = M();
                $a = $m->query("select * from user where user_name = '{$user_name}'");
                $e = $m->query("select * from user where mail = '{$user_name}'");
            var_dump($a);
                if (empty($a)) {
                    if (empty($e)) {
                        $this->error("用户不存在");
                    } else {
                        if ($e[0]['user_press'] == $password) {
                            $_SESSION["id"] = $e[0]['id'];
                            $_SESSION["user_name"] = $e[0]['user_name'];
                            $_SESSION["avatarulr"] = $e[0]['avatarulr'];
                            $this->error("登陆完成",U('/index'),2);
                        } else {
                            $this->error("密码错误");
                        }
                    }
                } else {
                    if ($a[0]['user_press'] == $password || $a[0]['user_press'] == $password) {
                        $_SESSION["id"] = $a[0]['id'];
                        $_SESSION["user_name"] = $a[0]['user_name'];
                        $_SESSION["avatarulr"] = $a[0]['avatarulr'];
                        $this->error("登陆完成",U('/index'),2);
                    } else {
                        $this->error("密码错误");
                    }
                }
            } else {
                $this->display("index");
            }

        }else{
            $this->error("无效操作",U('/index'),2);
        }
    }

}